home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / elk.init < prev    next >
Text File  |  1999-04-19  |  9KB  |  300 lines

  1. ;;;"elk.init" Initialisation file for SLIB for ELK 2.1    -*- Scheme -*-
  2. ;;; Author: Aubrey Jaffer
  3. ;;;
  4. ;;; This code is in the public domain.
  5.  
  6. ; No guarantees are given about the correctness of any of the
  7. ; choices made below.  Only enough work was done to get the require
  8. ; mechanism to work correctly.
  9. ;
  10. ; Stephen J. Bevan <bevan@cs.man.ac.uk> 19920912 modified by Mike
  11. ; Sperber to work correctly with statically-linked Elk and slib1d.  Be
  12. ; sure to change the library vicinities according to your local
  13. ; configuration.  If you're running MS-DOS (which is possible since
  14. ; 2.1), you probably have to change this file to make everything work
  15. ; correctly.
  16.  
  17. ;;; (software-type) should be set to the generic operating system type.
  18. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  19.  
  20. (define (software-type) 'UNIX)
  21.  
  22. ;;; (scheme-implementation-type) should return the name of the scheme
  23. ;;; implementation loading this file.
  24.  
  25. (define (scheme-implementation-type) 'Elk)
  26.  
  27. ;;; (scheme-implementation-home-page) should return a (string) URL
  28. ;;; (Uniform Resource Locator) for this scheme implementation's home
  29. ;;; page; or false if there isn't one.
  30.  
  31. (define (scheme-implementation-home-page)
  32.   "http://www.informatik.uni-bremen.de/~net/elk/")
  33.  
  34. ;;; (scheme-implementation-version) should return a string describing
  35. ;;; the version the scheme implementation loading this file.
  36.  
  37. (define (scheme-implementation-version) "3.0")
  38.  
  39. ;;; (implementation-vicinity) should be defined to be the pathname of
  40. ;;; the directory where any auxillary files to your Scheme
  41. ;;; implementation reside.
  42.  
  43. (define (implementation-vicinity)
  44.   (case (software-type)
  45.     ((UNIX)     "/usr/local/lib/elk-2.1/scm/")
  46.     ((VMS)    "scheme$src:")
  47.     ((MS-DOS)    "C:\\scheme\\")))
  48.  
  49. ;;; (library-vicinity) should be defined to be the pathname of the
  50. ;;; directory where files of Scheme library functions reside.
  51.  
  52. (require 'unix)
  53. (define getenv unix-getenv)
  54. (define system unix-system)
  55.  
  56. (define library-vicinity
  57.   (let ((library-path
  58.      (or (getenv "SCHEME_LIBRARY_PATH")
  59.          ;; Uses this path if SCHEME_LIBRARY_PATH is not defined.
  60.          (case (software-type)
  61.            ((UNIX) "/usr/local/lib/slib/")
  62.            ((VMS) "lib$scheme:")
  63.            ((MS-DOS) "C:\\SLIB\\")
  64.            (else "")))))
  65.     (lambda () library-path)))
  66.  
  67. ;;; (home-vicinity) should return the vicinity of the user's HOME
  68. ;;; directory, the directory which typically contains files which
  69. ;;; customize a computer environment for a user.
  70.  
  71. (define home-vicinity
  72.   (let ((home-path (getenv "HOME")))
  73.     (lambda () home-path)))
  74.  
  75. ;;; *features* should be set to a list of symbols describing features
  76. ;;; of this implementation.  Suggestions for features are:
  77.  
  78. (define *features*
  79.       '(
  80.     source                ;can load scheme source files
  81.                     ;(slib:load-source "filename")
  82.     compiled            ;can load compiled files
  83.                     ;(slib:load-compiled "filename")
  84.     rev4-report
  85.     ieee-p1178
  86.     sicp
  87.     rev4-optional-procedures
  88.     rev3-procedures
  89.     rev2-procedures
  90.     multiarg/and-
  91.     multiarg-apply
  92.     delay
  93.     transcript
  94.     full-continuation
  95.     sort
  96.     format
  97.     system
  98.     getenv
  99.     program-arguments
  100.     string-port
  101.     ))
  102.  
  103. ;------------
  104.  
  105. (define program-arguments
  106.   (lambda ()
  107.     (cons "undefined-program-name" (command-line-args))))
  108.  
  109. ; EXACT? appears to always return #f which isn't very useful.
  110. ; Approximating it with INTEGER? at least means that some
  111. ; of the code in the library will work correctly
  112.  
  113. (define exact? integer?)  ; WARNING: redefining EXACT?
  114.  
  115. (define (inexact? arg)
  116.   (not (exact? arg)))
  117.  
  118. ;;; (TMPNAM) makes a temporary file name.
  119. (define tmpnam
  120.   (let ((cntr 100))
  121.     (lambda () (set! cntr (+ 1 cntr))
  122.         (let ((tmp (string-append "slib_" (number->string cntr))))
  123.           (if (file-exists? tmp) (tmpnam) tmp)))))
  124.  
  125. ; Pull in GENTENV and SYSTEM
  126.  
  127. ;;; (FILE-EXISTS? <string>) already here.
  128.  
  129. ;;; (DELETE-FILE <string>)
  130. (define (delete-file f) (system (string-append "rm " f)))
  131.  
  132. ;------------
  133.  
  134. ;;; (OUTPUT-PORT-WIDTH <port>)
  135. (define (output-port-width . arg) 79)
  136.  
  137. ;;; (OUTPUT-PORT-HEIGHT <port>)
  138. (define (output-port-height . arg) 24)
  139.  
  140. ;;; (CURRENT-ERROR-PORT)
  141. ;;; is already defined in Elk 2.1
  142.  
  143. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  144. ;;; use this definition if your system doesn't have such a procedure.
  145. (define force-output flush-output-port)
  146.  
  147. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  148. ;;; port versions of CALL-WITH-*PUT-FILE.
  149. (define (call-with-output-string f)
  150.   (let ((outsp (open-output-string)))
  151.     (f outsp)
  152.     (let ((s (get-output-string outsp)))
  153.       (close-output-port outsp)
  154.       s)))
  155.  
  156. (define (call-with-input-string s f)
  157.   (let* ((insp (open-input-string s))
  158.      (res (f insp)))
  159.     (close-input-port insp)
  160.     res))
  161.  
  162. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  163. ;;; be returned by CHAR->INTEGER.
  164. (define char-code-limit 256)
  165.  
  166. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  167. (define most-positive-fixnum 8388608)  ; 23 bit integers ?
  168.  
  169. ;;; Return argument
  170. (define (identity x) x)
  171.  
  172. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  173. (define slib:eval eval)
  174.  
  175. (define *macros* '())
  176. (define (defmacro? m) (and (assq m *macros*) #t))
  177.  
  178. (define-macro (defmacro key pattern . body)
  179.   `(begin
  180.      (define-macro ,(cons key pattern) ,@body)
  181.      (set! *macros* (cons (cons ',key (lambda ,pattern ,@body)) *macros*))))
  182.  
  183. (define (macroexpand-1 e)
  184.   (if (pair? e) (let ((a (car e)))
  185.           (cond ((symbol? a) (set! a (assq a *macros*))
  186.                      (if a (apply (cdr a) (cdr e)) e))
  187.             (else e)))
  188.       e))
  189.  
  190. (define (macroexpand e)
  191.   (if (pair? e) (let ((a (car e)))
  192.           (cond ((symbol? a)
  193.              (set! a (assq a *macros*))
  194.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  195.             (else e)))
  196.       e))
  197.  
  198. (define gentemp
  199.   (let ((*gensym-counter* -1))
  200.     (lambda ()
  201.       (set! *gensym-counter* (+ *gensym-counter* 1))
  202.       (string->symbol
  203.        (string-append "slib:G" (number->string *gensym-counter*))))))
  204.  
  205. (define defmacro:eval slib:eval)
  206. (define defmacro:load load)
  207. ;;; If your implementation provides R4RS macros:
  208. ;(define macro:eval slib:eval)
  209. ;(define macro:load load)
  210.  
  211. (define (slib:eval-load <pathname> evl)
  212.   (if (not (file-exists? <pathname>))
  213.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  214.   (call-with-input-file <pathname>
  215.     (lambda (port)
  216.       (let ((old-load-pathname *load-pathname*))
  217.     (set! *load-pathname* <pathname>)
  218.     (do ((o (read port) (read port)))
  219.         ((eof-object? o))
  220.       (evl o))
  221.     (set! *load-pathname* old-load-pathname)))))
  222.  
  223. (define slib:warn
  224.   (lambda args
  225.     (let ((port (current-error-port)))
  226.       (display "Warn: " port)
  227.       (for-each (lambda (x) (display x port)) args))))
  228.  
  229. ;;; define an error procedure for the library
  230. (define slib:error
  231.   (lambda args
  232.     (let ((port (open-output-string))
  233.       (err (if (and (pair? args) (symbol? (car args)))
  234.            (car args) 'slib))
  235.       (args (if (and (pair? args) (symbol? (car args)))
  236.             (cdr args) args)))
  237.       (for-each (lambda (x) (display x port) (display " " port)) args)
  238.       (let ((str (get-output-string port)))
  239.     (close-output-port port)
  240.     (error err str)))))
  241.  
  242. ;;; define these as appropriate for your system.
  243. (define slib:tab #\tab)
  244. (define slib:form-feed #\formfeed)
  245.  
  246. ;;; Define these if your implementation's syntax can support it and if
  247. ;;; they are not already defined.
  248.  
  249. ;(define (1+ n) (+ n 1))
  250. ;(define (-1+ n) (+ n -1))
  251. ;(define 1- -1+)
  252.  
  253. (define in-vicinity string-append)
  254.  
  255. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  256. ;;; return if exitting not supported.
  257. (define slib:exit
  258.   (lambda args
  259.     (exit (cond ((null? args) 0)
  260.         ((eqv? #t (car args)) 0)
  261.         ((and (number? (car args)) (integer? (car args))) (car args))
  262.         (else 1)))))
  263.  
  264. ;;; Here for backward compatability
  265. (define scheme-file-suffix
  266.   (let ((suffix (case (software-type)
  267.           ((NOSVE) "_scm")
  268.           (else ".scm"))))
  269.     (lambda () suffix)))
  270.  
  271. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  272. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  273.  
  274. ; Modify the already modified _load_ so that it copes with
  275. ; environments correctly.  The change involves using
  276. ; _(global-environment)_ if none is explicitly specified.
  277. ; If this is not done, definitions in files loaded by other files will
  278. ; not be loaded in the correct environment.
  279.  
  280. (define slib:load-source
  281.   (let ((primitive-load load))
  282.     (lambda (<pathname> . rest)
  283.       (let ((env (if (null? rest) (list (global-environment)) rest)))
  284.     (apply primitive-load <pathname> env)))))
  285.  
  286. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  287. ;;; by compiling "foo.scm" if this implementation can compile files.
  288. ;;; See feature 'COMPILED.
  289.  
  290. (define slib:load-compiled
  291.   (let ((primitive-load load))
  292.     (lambda (<pathname> . rest)
  293.       (apply primitive-load (string->symbol (string-append name ".o")) rest))))
  294.  
  295. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  296.  
  297. (define slib:load slib:load-source)    ;WARNING: redefining LOAD
  298.  
  299. (slib:load (in-vicinity (library-vicinity) "require"))
  300.